# -*- coding:utf-8 -*-
import binascii
import importlib
import sys
import codecs
import serial

importlib.reload(sys)

ser = serial.Serial("/dev/ttySC0", 9600)
ser.flushInput()


s = "page homepage"
# 字符串变gbk字符型字节流
s_byte = s.encode("gbk")
# 字符型字节流转十六进制字节流, 与b2a_hex()，bytes.hex()方法功能一样
s_hex = binascii.hexlify(s_byte)
s_hex = s_hex + b'FFFFFF'
# 十六进制字节流解码
s_gbk = codecs.decode(s_hex, 'hex')
ser.write(s_gbk)
